<?php

declare(strict_types=1);

namespace app\api\model;

use Carbon\Carbon;
use think\Model;

/**
 * 用户模型
 */
class User extends Model
{
    protected $table = 'evt_member';

    public function dtsRecord(): \think\model\relation\HasMany
    {
        return $this->hasMany(DtsRecord::class, 'user_id', 'id');
    }


    public function pointsLog()
    {
        return $this->hasMany(UserPointsLog::class, 'user_id', 'id');
    }

    public function dtsRank()
    {
        return $this->hasMany(DtsRecord::class, 'user_id', 'id')
            ->where('create_time', '>=', Carbon::yesterday()->startOfWeek()->timestamp)
            ->where('create_time', '<=', Carbon::yesterday()->endOfWeek()->timestamp);
    }

    public function dtsRank2()
    {
        return $this->hasMany(DtsRecord::class, 'user_id', 'id')
            ->where('create_time', '>=', Carbon::now()->startOfWeek()->timestamp)
            ->where('create_time', '<=', Carbon::now()->endOfWeek()->timestamp);
    }



}
